package com.bjsxt.shoppingOnline.shopping_common.util;

import org.apache.commons.codec.digest.DigestUtils;

public class EncryptUtil
{
	public static String encodeStr(String pass)
	{
		RegexUtil regexUtil=new RegexUtil();
		String encType="sha256";
		String randStr=regexUtil.proccedStr(32);
		String encHead=encType+"$"+randStr+"$";
		String encBack=DigestUtils.sha256Hex(encHead+pass);
		
		return encHead+encBack;
	}
	public static boolean checkStr(String resultStr,String pass)
	{
		String[] str=resultStr.split("\\$");
		String encHead=str[0]+"$"+str[1]+"$";
		String encBack=DigestUtils.sha256Hex(encHead+pass);
		if((encHead+encBack).equals(resultStr))
		{
			return true;
		}
		return false;
		
	}
	
	public static void main(String[] args)
	{
		EncryptUtil encryptUtil=new EncryptUtil();
		String str=encryptUtil.encodeStr("111111");
		boolean bool=encryptUtil.checkStr(str, "112111");
		System.out.println(bool);
	}
	
	
}
